package com.example.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.Toast;

import java.util.ArrayList;

public class Game extends AppCompatActivity implements View.OnClickListener {

    private GridView mGridView;
    private String[] channelDec;
    private int[] channelImg;
    private ArrayList<Channel> channelList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);
        initChannelView();
        initView();
    }



    private void initChannelView()
    {
        mGridView = (GridView) findViewById(R.id.channel);

        channelImg = new int []
                {
                        R.id.pubg,
                        R.id.pubg,
                        R.id.pubg,
                        R.id.pubg,
                        R.id.pubg,
                        R.id.pubg,


                };

        channelDec = new String[]
                {
                        "永劫无间",
                        "彩虹六号",
                        "怪物猎人",
                        "尼尔机械纪元",
                        "鬼泣五",
                        "PUBG",
                };

        channelList = new ArrayList<>();
        for(int i=0;i<channelDec.length;i++)
        {
            Channel channel = new Channel();
            channel.setImgId(channelImg[i]);
            channel.setDec(channelDec[i]);
            channelList.add(channel);
        }

        mGridView.setAdapter(new ChannelAdapter(channelList,this));

        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                switch (position) {
                    case 0:
                        Toast.makeText(Game.this, "社区开发中，敬请期待", Toast.LENGTH_SHORT).show();
                        break;
                    case 1:
                        Toast.makeText(Game.this, "社区开发中，敬请期待", Toast.LENGTH_SHORT).show();
                    default:
                        Toast.makeText(Game.this, "社区开发中，敬请期待", Toast.LENGTH_SHORT).show();
                        break;


                }
            }
        });
    }
    private void initView()
    {
        ImageButton home = findViewById(R.id.home);
        ImageButton msg = findViewById(R.id.msg);
        ImageButton me = findViewById(R.id.me);
        home.setOnClickListener(this);
        msg.setOnClickListener(this);
        me.setOnClickListener(this);
    }

    public void onClick (View v)
    {
        switch (v.getId())
        {
            case R.id.home:
                Intent intent = new Intent(Game.this,MainActivity.class);
                startActivity(intent);
                overridePendingTransition(0,0);
                finish();
                break;
            case R.id.msg:
                Intent intent1 = new Intent(Game.this,Msg.class);
                startActivity(intent1);
                overridePendingTransition(0,0);
                finish();
                break;
            case R.id.me:
                Intent intent2 = new Intent(Game.this,Me.class);
                startActivity(intent2);
                overridePendingTransition(0,0);
                finish();
                break;
        }
    }
}